package com.example.hzcf.gesturelock_master;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

import java.util.concurrent.locks.Lock;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    public static final String TAG="MainActivity";
    public static final String LOCK="lock";
    public static final String LOCK_KEY="lock_key";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SharedPreferences preferences=getSharedPreferences(LOCK,MODE_PRIVATE);
        String lockPattenString=preferences.getString(LOCK_KEY,null);
        if (lockPattenString !=null){
            Intent intent=new Intent(this,LockActivity.class);
            startActivity(intent);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.lock:
                Intent intent=new Intent(this,LockSetupActivity.class);
                startActivity(intent);
                break;
            case R.id.unlock:
                getSharedPreferences(LOCK,MODE_PRIVATE).edit().clear().commit();
                break;
            default:
                break;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main,menu);
        return true;
    }
}
